package org.hxyjs.service.impl;

import org.hxyjs.dao.ActivetyrecordDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Activetyrecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ActivetyrecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("ActivetyrecordService")
public class ActivetyrecordServiceImpl implements ActivetyrecordService {
    @Resource
    ActivetyrecordDao activetyrecordDao;
    @Override
    public DTO<Activetyrecord> getAllActivetyrecords()  throws Exception{
        List<Activetyrecord> activetyrecords = activetyrecordDao.getAllActivetyrecords();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(activetyrecords).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Activetyrecord>(messageEnum.getCode(),messageEnum.getMessage(),activetyrecords);
    }

    @Override
    public DTO<Activetyrecord> deleteActivetyrecordByAfno(String afno)  throws Exception{
        Integer result = activetyrecordDao.deleteActivetyrecordByAfno(afno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEADMINSUCCESS:MessageEnum.DELETEADMINFAIL;
        return new DTO<Activetyrecord>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Activetyrecord> getActivetyrecordByAfno(String afno)  throws Exception{
        Activetyrecord activetyrecords = activetyrecordDao.getActivetyrecordByAfno(afno);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(activetyrecords).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Activetyrecord>(messageEnum.getCode(),messageEnum.getMessage(),activetyrecords);
    }

    @Override
    public DTO<Activetyrecord> updateActivetyrecordByAfno(Activetyrecord activetyrecord) throws Exception {
        Integer result = activetyrecordDao.updateActivetyrecordByAfno(activetyrecord);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEADMINSUCCESS:MessageEnum.UPDATEADMINFAIL;
        return new DTO<Activetyrecord>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Activetyrecord> addActivetyrecord(Activetyrecord activetyrecord) throws Exception {
        Integer result = activetyrecordDao.addActivetyrecord(activetyrecord);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  =result> 0?MessageEnum.ADDADMINSUCCESS:MessageEnum.ADDADMINFAIL;
        return new DTO<Activetyrecord>(messageEnum.getCode(),messageEnum.getMessage());
    }

    /**
     * 学生选课成功 学生成绩加1分，从选课信息中可以获得学生的学号就能查询出学生原来的成绩
     * @param
     * @return
     * @throws Exception
     */
    @Override
    public DTO<Activetyrecord> getActivetyrecordByPage(PageInfo pageInfo) throws Exception {
        List<Activetyrecord> activetyrecords = activetyrecordDao.getActivetyrecordByPage(pageInfo);
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum  = Optional.ofNullable(activetyrecords).isPresent()?MessageEnum.GETADMINSUCCESS:MessageEnum.GETADMINFAIL;
        return new DTO<Activetyrecord>(messageEnum.getCode(),messageEnum.getMessage(),activetyrecords,pageInfo);
    }

}
